<!-- 
文件名称: permission_management.html
完整存储路径: frontend/templates/permission_management.html
功能说明: 
    权限管理页面，展示静态配置中已定义的权限，支持启用/禁用权限。
    基于配置驱动的权限管理，确保权限定义的一致性。
使用说明:
    通过AJAX请求从后端API获取权限数据并展示，支持对权限的启用/禁用操作。
    权限定义来自静态配置文件，确保系统权限的标准化。
-->

{% extends "layouts/base.html" %}
{% block title %}权限管理 - 近视预防干预系统{% endblock %}
{% block content %}
<main class="main-content-container">
  <div class="user-management-content">
    <h1>权限管理</h1>
    <p class="text-muted">管理系统中已定义的权限，支持启用/禁用权限功能</p>
    
    <div class="permission-modules">
      <!-- 权限模块将通过JavaScript动态加载 -->
    </div>
  </div>
</main>

<!-- 权限详情模态框 -->
<div id="permissionDetailModal" class="modal" style="display: none">
  <div class="modal-content">
    <div class="modal-header">
      <h2 id="modalTitle">权限详情</h2>
      <span class="close">&times;</span>
    </div>
    <div class="modal-body">
      <div class="permission-info">
        <div class="form-group">
          <label>权限代码</label>
          <input type="text" id="permissionCode" readonly class="form-control" />
        </div>
        <div class="form-group">
          <label>权限名称</label>
          <input type="text" id="permissionName" readonly class="form-control" />
        </div>
        <div class="form-group">
          <label>描述</label>
          <textarea id="permissionDescription" readonly class="form-control" rows="3"></textarea>
        </div>
        <div class="form-group">
          <label>状态</label>
          <select id="permissionStatus" class="form-control">
            <option value="enabled">启用</option>
            <option value="disabled">禁用</option>
          </select>
        </div>
      </div>
    </div>
    <div class="modal-footer">
      <button type="button" class="btn btn-secondary" onclick="closeModal()">取消</button>
      <button type="button" class="btn btn-primary" onclick="savePermission()">保存</button>
    </div>
  </div>
</div>
{% endblock %}

{% block styles %} 
{{ super() }}
<link rel="stylesheet" href="{{ url_for('static', filename='css/user_management.css') }}" />
<style>
.permission-modules {
  margin-top: 20px;
}

.permission-module {
  border: 1px solid #ddd;
  border-radius: 8px;
  margin-bottom: 20px;
  overflow: hidden;
}

.module-header {
  background-color: #f8f9fa;
  padding: 15px 20px;
  border-bottom: 1px solid #ddd;
  font-weight: bold;
  color: #495057;
}

.module-content {
  padding: 0;
}

.permission-item {
  display: flex;
  align-items: center;
  padding: 12px 20px;
  border-bottom: 1px solid #eee;
  transition: background-color 0.2s;
}

.permission-item:hover {
  background-color: #f8f9fa;
}

.permission-item:last-child {
  border-bottom: none;
}

.permission-info {
  flex: 1;
}

.permission-code {
  font-family: monospace;
  color: #6c757d;
  font-size: 0.9em;
  margin-bottom: 4px;
}

.permission-name {
  font-weight: 500;
  color: #212529;
  margin-bottom: 2px;
}

.permission-description {
  color: #6c757d;
  font-size: 0.9em;
}

.permission-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.status-badge {
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 0.8em;
  font-weight: 500;
}

.status-enabled {
  background-color: #d4edda;
  color: #155724;
}

.status-disabled {
  background-color: #f8d7da;
  color: #721c24;
}

.btn-edit {
  padding: 4px 8px;
  font-size: 0.8em;
}

.modal {
  display: none;
  position: fixed;
  z-index: 1000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0,0,0,0.5);
}

.modal-content {
  background-color: #fefefe;
  margin: 5% auto;
  padding: 0;
  border-radius: 8px;
  width: 500px;
  max-width: 90%;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.modal-header {
  padding: 20px;
  border-bottom: 1px solid #dee2e6;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h2 {
  margin: 0;
  font-size: 1.5em;
}

.close {
  color: #aaa;
  font-size: 28px;
  font-weight: bold;
  cursor: pointer;
}

.close:hover {
  color: #000;
}

.modal-body {
  padding: 20px;
}

.modal-footer {
  padding: 15px 20px;
  border-top: 1px solid #dee2e6;
  text-align: right;
}

.form-group {
  margin-bottom: 15px;
}

.form-group label {
  display: block;
  margin-bottom: 5px;
  font-weight: 500;
  color: #495057;
}

.form-control {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid #ced4da;
  border-radius: 4px;
  font-size: 14px;
}

.form-control:focus {
  outline: none;
  border-color: #80bdff;
  box-shadow: 0 0 0 0.2rem rgba(0,123,255,.25);
}

.form-control[readonly] {
  background-color: #e9ecef;
  cursor: not-allowed;
}
</style>
{% endblock %}

{% block scripts %} 
{{ super() }}
<script src="{{ url_for('static', filename='js/permission_management.js') }}"></script>
{% endblock %}

